package com.test.ssm.controller;

import com.test.ssm.pojo.User;
import com.test.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author 徒有琴
 */
@Controller
public class SystemController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(String username, String password, Model model, HttpSession session) {
        User user = userService.doLogin(username, password);
        if (user == null) {
            model.addAttribute("message", "用户名或密码错误");
            return "login";
        }
        session.setAttribute("user", user);
        return "redirect:goindex";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "login";
    }
    @RequestMapping("/")
    public String welcome() {
        return "login";
    }
    @RequestMapping("/go{name}")
    public String page(@PathVariable String name) {
        return name;
    }
}
